<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <script src="../js/vue-router_3.0.2.js"></script>

  </head>
  <body>
    <div id="div1">
        <router-link to="/users" >用户模块</router-link>
        <router-link to="/products" >商品模块</router-link>
        <!-- 占位符: 显示点击的组件对应的模板内容 -->
        <router-view></router-view>    <!--占位符，会被routes数组里面的component代替-->
    </div>
    <script>
      const user_con = {
        template: '<h1>用户模块</h1>'
      }

      const product_con = {
        template: '<h1>商品模块</h1>'
      }

      // 创建路由对象
      const router = new VueRouter({
        /* 
          配置路由规则
            通过path来映射 路径 -> 组件
         */
        routes: [
          { path: '/users',component: user_con },
          { path: '/products',component: product_con }
        ]
      })

      const vm = new Vue({
        el: '#div1',
        data: {},
        // 挂载路由对象
        // router:router 写法一
        router
        
      })
    </script>
  </body>
</html>